package com.example.musicapp.view;


import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import android.widget.Toast;

import com.example.musicapp.R;
import com.example.musicapp.application.MyApp;
import com.example.musicapp.base.BaseActivity;
import com.example.musicapp.contract.IRegisterContract;
import com.example.musicapp.presenter.RegisterPresenter;

import static com.example.musicapp.utils.Constant.PHONE_NO_MATCH;


public class RegisterActivity extends BaseActivity<IRegisterContract.IRegisterPre> implements IRegisterContract.IRegisterUi,View.OnClickListener {


    private EditText mEtName;
    public static final String TAG = "";
    private EditText mEtRegisterAccount;
    private EditText mEtCode;
    private EditText mEtRegisterPassword;
    private int mRegisterResult;
    private Button mBtnSendMessage;
    private int mScanNum;
    @Override
    public IRegisterContract.IRegisterPre onBindPresenter() {
        return new RegisterPresenter(this);
    }



    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mEtRegisterAccount = findViewById(R.id.et_register_account);
        mEtCode = findViewById(R.id.et_register_password1);
        mEtRegisterPassword = findViewById(R.id.et_register_password2);
        mBtnSendMessage = findViewById(R.id.btn_send_message);
        Button btnRegister = findViewById(R.id.btn_register_register);
        mEtName = findViewById(R.id.et_name);

        btnRegister.setOnClickListener(this);
        mBtnSendMessage.setOnClickListener(this);
    }

    @Override
    public void initListener() {

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_register;
    }

    @Override
    public void registerSuccess() {

    }

    @Override
    public void registerFailure() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_register_register:

                register(mScanNum);
                break;
            case R.id.btn_send_message:
                mScanNum =  getPresenter().requestSendMessage(mEtRegisterAccount.getText().toString());
                break;
            default:break;
        }
    }



    private void register(int scanNum){
        switch (scanNum){
            case PHONE_NO_MATCH:
                Toast.makeText(MyApp.getContext(),"请输入正确的手机格式",Toast.LENGTH_LONG).show();

                return;
            default:

                getPresenter().register(mEtRegisterAccount.getText().toString(),mEtRegisterPassword.getText().toString(),mEtCode.getText().toString(),mEtName.getText().toString());

        }

    }
}